package main

import (
	"flag"
	"fmt"
	"gitee.com/taadis/xkcder/client"
	"log"
	"time"
)

func main() {
	fmt.Println("xkcder")

	//
	comicNum := flag.Int("n", 0, "要拉取的漫画编号 (默认 0 表示最新)")
	timeout := flag.Int64("t", client.DefaultClientTimeout.Milliseconds(), "请求超时时间 (默认 30 * 1000 毫秒)")
	isSave := flag.Bool("s", false, "是否保存漫画图片到当前目录 (默认 false)")
	outputType := flag.String("o", "text", "打印输出的格式, 如: text/json (默认 text)")
	flag.Parse()

	//
	xkcdClient := client.NewClient()
	xkcdClient.SetTimeout(time.Duration(*timeout) * time.Second)
	comic, err := xkcdClient.Fetch(*comicNum, *isSave)
	if err != nil{
		log.Println(err)
	}

	if *outputType == "json"{
		fmt.Println(comic.JSON())
	} else {
		fmt.Println(comic.Pretty())
	}
}
